package objbo.xmlparser.view.ui;

import objbo.xmlparser.model.bean.ElementBean;
import objbo.xmlparser.view.interfaces.InterFaceMain;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class TabUI extends Composite implements IParserUI
{

	private ElementListUI elementListUI = null;
	private AttributeListUI attributeListUI = null;
	private ContentUI contentUI = null;
	
	
	private InterFaceMain interfaces = null;
	
	public TabUI(Composite parent, InterFaceMain interfaces)
	{
		super(parent, SWT.NONE);
		this.interfaces = interfaces;
		initComposite();
	}
	
	public TabUI(Composite parent)
	{
		super(parent, SWT.NONE);
		this.interfaces = interfaces;
		initComposite();
	}

	private void initComposite()
	{
		TabFolder tabFolder = null;
		
		
		TabItem elementTabItem = null;
		
		
		TabItem attributeTabItem = null;
		
		
		TabItem contentTabItem = null;
		
		
		Layout layout = null;
		
		
		try
		{

			tabFolder = new TabFolder(this, SWT.NONE);
			
			layout = new FillLayout(SWT.VERTICAL);
			this.setLayout(layout);
			
			if(this.interfaces == null)
			{
				this.elementListUI = new ElementListUI(tabFolder);
				this.attributeListUI = new AttributeListUI(tabFolder);
				this.contentUI = new ContentUI(tabFolder);
			}
			else
			{
				this.elementListUI = new ElementListUI(tabFolder,interfaces);
				this.attributeListUI = new AttributeListUI(tabFolder,interfaces);
				this.contentUI = new ContentUI(tabFolder,interfaces);
			}
						

			elementTabItem = new TabItem(tabFolder, SWT.NONE);
			elementTabItem.setText("Elements");
			elementTabItem.setControl(elementListUI);
			
			
			attributeTabItem = new TabItem(tabFolder, SWT.NONE);
			attributeTabItem.setText("Attributes");
			attributeTabItem.setControl(attributeListUI);
			
						
			contentTabItem = new TabItem(tabFolder, SWT.NONE);
			contentTabItem.setText("Contents");
			contentTabItem.setControl(contentUI);
			
			tabFolder.pack();
			
			
			
			
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
	}
	
	
	
	public void setInterfaces(InterFaceMain interfaces)
	{
		this.interfaces = interfaces;
		this.elementListUI.setInterfaces(interfaces);
		this.attributeListUI.setInterfaces(interfaces);
		this.contentUI.setInterfaces(interfaces);
	}

	public void clear()
	{
		this.elementListUI.clear();
		this.attributeListUI.clear();
		this.contentUI.clear();
	}
	
	public void setData(ElementBean elementBean)
	{
//		if(elementBean == null)
//		{
//			System.out.println("TabUI.setData : elementBean null");
//			return;
//		}
		
		
		
		
		if(elementBean != null)
		{
			this.contentUI.setData(elementBean);
			this.elementListUI.setData(elementBean);
			this.attributeListUI.setData(elementBean);
		}

		
	}

	public ElementListUI getElementListUI()
	{
		return elementListUI;
	}

	public AttributeListUI getAttributeListUI()
	{
		return attributeListUI;
	}

	public ContentUI getContentUI()
	{
		return contentUI;
	}
	
	
	
	

}
